package src.model.gameWorld.pathfinding.astar.heuristic;

import src.model.gameObject.GameObject;
import src.model.gameWorld.Position;
import src.model.gameWorld.pathfinding.PathfindingMap;
import src.model.gameWorld.pathfinding.movement.DoubleMovementCost;
import src.model.gameWorld.pathfinding.movement.Movement;
import src.model.gameWorld.pathfinding.movement.MovementCost;

/**
 * <b>Overview</b>
 * The StraightLinePathfindingHeuristic uses the broadway approach to estimating movement cost.  This is used by the pathfinder to estimate the value of moving to a particular position.
 *
 * <b>Responsibilities</b>
 * Give an approximation to the movement cost of getting from one map position to another.
 *
 * <b>Collaborators</b>
 * Position - Subcontractor: Positions maintain location information for each map location that allows a quick calculation.
 * PathfindingMap - Subcontractor: the PathfindingMap maintains the adjacency information used to quickly calculate the distance between two positions.
 *
 * <b>Implementor</b> - Bruce
 * <b>Tester</b> - Tim
 *
 * @author Bruce
 */
public final class StraightLinePathfindingHeuristic implements PathfindingHeuristic
{
	/**
	 * The Movement used to determine movement costs.
	 */
	private Movement movement;

	/**
	 * The PathfindingMap over which to determine movement cost.
	 */
	private PathfindingMap pathfindingMap;

	/**
	 * Creates a new StraightLinePathfindingHeuristic.
	 *
	 * @param pathfindingMap the PathfindingMap to pathfind over.
	 * @param movement the Movement to use for cost calculations.
	 * @throws NullPointerException if either argument is <code>null</code>.
	 */
	public StraightLinePathfindingHeuristic(PathfindingMap pathfindingMap, Movement movement) throws NullPointerException
	{
		if(pathfindingMap == null || movement == null)
			throw new NullPointerException();

		this.pathfindingMap = pathfindingMap;
		this.movement = movement;
	}

	/* (non-Javadoc)
	 * @see pathfindingMap.pathfinding.astar.heuristic.PathfindingHeuristic#getHeuristicCost(pathfindingMap.Location, pathfindingMap.Location)
	 */
	public MovementCost getHeuristicCost(GameObject mover, Position start, Position destination)
	{
		if(start.equals(destination))
			return new DoubleMovementCost(0.0);
		return movement.getMovementCost(mover, pathfindingMap.getDirectionTo(start, destination), destination);
	}
}